<template>
  <div class="card" :style="{ width: width || '20%' }" @click.stop="toDetail">
    <!-- 横向小卡片(一行站四个) -->
    <div
      class="img-box"
      :style="{ backgroundImage: `url(${item.cover})` }"
    ></div>
    <div class="my-text title">{{ item.title }}</div>
    <div class="my-text author" v-if="!countdown">{{ item.author }}</div>
    <div class="free" v-else>
      <div class="wprice">{{ item.wprice }} 阅点/千字</div>
      <div class="discountDesc">{{ item.discountDesc }}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["item", "width", "countdown"],
  methods: {
    toDetail() {
      this.$router.push({
        name: "detail",
        params: {
          bookid: this.item.id,
          title: this.item.title,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.card {
  .img-box {
    position: relative;
    aspect-ratio: 73 / 105;
    &::after {
      position: absolute;
      left: 0;
      bottom: -0.1rem;
      content: "";
      display: block;
      width: 100%;
      height: 0.1rem;
      background-image: linear-gradient(
        to bottom,
        var(--bgc-gray),
        rgba(#fafafa, 0)
      );
      filter: blur(0.02rem);
    }
  }
  .title {
    font-size: 0.14rem;
    margin: 0 0 0.05rem 0;
    font-weight: bold;
  }
  .author {
    font-size: 0.12rem;
    color: var(--text-gray);
  }
  .free {
    font-size: 0.12rem;
    color: var(--text-gray);
    .wprice {
      text-decoration: line-through;
      margin-bottom: 0.05rem;
    }
    .discountDesc {
      color: var(--text-red);
    }
  }
}
</style>